import { CopyInfoPanelBase } from "../../CopyInfoPanelBase";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { FilterConst } from "../../../../../component/gconst/FilterConst";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GuildRobCityCopyThreeListRenderer } from "./GuildRobCityCopyThreeListRenderer";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { SRobCityThreeCopyInfo } from "../../../../../../Message/Public/SRobCityThreeCopyInfo";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { TBoss } from "../../../../../../Message/Db/Tables/TBoss";
import { BossConfig } from "../../../../resource/BossConfig";
import { SRobCityThreeStart } from "../../../../../../Message/Public/SRobCityThreeStart";
import { ClockManager } from "../../../../manager/ClockManager";
import { SecTimerView } from "../../../common/SecTimerView";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../../../com/mui/controls/GTileList";
import { Vector } from "../../../../../../__AS3__/vec/Vector";
//class GuildRobCityCopyThreeInfoPanel
    
    export  class GuildRobCityCopyThreeInfoPanel extends CopyInfoPanelBase
    {
        constructor(arg1: string="MagicTowerInfoButtonBg")
        {
            super(arg1);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            super.createChildren();
            _titleSp.buttonMode = true;
            _titleSp.addEventListener(flash.events.MouseEvent.CLICK, this.onTitleClickHandler);
            loc1 = new GTextFormat(FontUtil.songtiName, 12, 16776960, true);
            this._secTimer = ObjCreate.createSecTimeView(Language.getString(60923), 10, 10, 240, 20, _bodySp, loc1);
            this._secTimer.selectable = false;
            this._secTimer.filters = [FilterConst.glowFilter];
            this._bossInfoText = ObjCreate.createGTextField("", 10, 35, 240, 20, _bodySp, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat6, 3));
            this._bossInfoText.mouseEnabled = false;
            this._bossInfoText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._liftInfoText = ObjCreate.createGTextField("", 10, 10, 240, 20, _bodySp, GlobalStyle.textFormat4);
            this._liftInfoText.mouseEnabled = false;
            this._liftInfoText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._listSp = new Object /* flash.display.Sprite */();
            this._listSp.x = 10;
            _bodySp.addChild(this._listSp);
            var loc2=new GTextFormat(FontUtil.songtiName, 12, 6350622, true);
            ObjCreate.createGTextField(Language.getString(60961), 0, 0, 200, 20, this._listSp, loc2);
            ObjCreate.createGTextField(Language.getString(60963), 0, 20, 45, 20, this._listSp, loc2);
            ObjCreate.createGTextField(Language.getString(60944), 45, 20, 150, 20, this._listSp, loc2);
            ObjCreate.createGTextField(Language.getString(60962), 185, 20, 45, 20, this._listSp, GlobalStyle.getTextFormatCenter(loc2));
            this._listPanel = ObjCreate.createTileList(0, 40, 270, 90, this._listSp);
            this._listPanel.rowHeight = 20;
            this._listPanel.columnWidth = 245;
            this._listPanel.verticalScrollPolicy = "off";
            this._listPanel.setStyle("cellRenderer", GuildRobCityCopyThreeListRenderer);
            this._listDp = new DataProvider();
            this._rankLabel = ObjCreate.createGTextField("", 10, 10, 240, 20, _bodySp, new GTextFormat(null, 12, 16776960, true, null, true, null, null, flash.text.TextFormatAlign.RIGHT, null, 5));
            this._rankLabel.htmlText = "<u><a href=\'event: 0\'>" + Language.getString(60973) + "</a></u>";
            this._rankLabel.addEventListener(flash.events.TextEvent.LINK, this.onRankLabelClick);
            this.resize();
            return;
        }

        /* internal  */onRankLabelClick(arg1): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobCity_ShowCopyThreeRankPanel));
            return;
        }

        /* internal  */onTitleClickHandler(arg1): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobCity_ShowCopyThreeRankPanel));
            return;
        }

        public /* override */ updateInfos(arg1): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc1=arg1 as SRobCityThreeCopyInfo;
            if (loc1) 
            {
                if (!this._bossVec) 
                {
                    this.initBossVec(loc1.bossInfo);
                }
                loc2 = "";
                loc3 = 0;
                while (loc3 < this._bossVec.length) 
                {
                    loc2 = loc2 + ("\t" + this._bossVec[loc3].name + "\t" + (loc1.bossInfo[this._bossVec[loc3].code] != 1 ? Language.getString(60964) : Language.getString(60965)) + "\n");
                    ++loc3;
                }
                this._bossInfoText.htmlText = HTMLUtil.addColor(loc2, GlobalStyle.color1);
                this._liftInfoText.htmlText = HTMLUtil.addColor(Language.getString(60960) + loc1.lifePercentage + "%", "#FFFF00");
                this._listDp.removeAll();
                var loc5=0;
                var loc6=loc1.robCityThreeJoinTeams;
                for(loc4 of loc6) 
                {
                    if (!(loc4.shaBak <= 0)) 
                    {
                        continue;
                    }
                    this._listDp.addItem(loc4);
                }
                this._listDp.sortOn("hurt", Array.DESCENDING | Array.NUMERIC);
                this._listPanel.dataProvider = this._listDp;
            }
            this.resize();
            return;
        }

        /* internal  */initBossVec(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc1=null;
            var loc2=null;
            this._bossVec = new Vector.<TBoss>();
            var loc3=0;
            var loc4=arg1;
            for (loc2 in loc4) 
            {
                loc1 = BossConfig.instance.getInfoByName(parseInt(loc2));
                if (!loc1) 
                {
                    continue;
                }
                this._bossVec.push(loc1);
            }
            return;
        }

        public updateLeftTime(arg1: SRobCityThreeStart, arg2: Boolean): void
        {
            if (arg1) 
            {
                if (arg2) 
                {
                    this._secTimer.setParse(Language.getString(60923));
                    this._secTimer.setLeftTime((arg1.endDt.time - ClockManager.instance.nowDate.time) / 1000);
                }
                else 
                {
                    this._secTimer.setParse(Language.getString(60922));
                    this._secTimer.setLeftTime((arg1.startDt.time - ClockManager.instance.nowDate.time) / 1000);
                }
            }
            return;
        }

        public stopCountDown(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            return;
        }

        public clean(): void
        {
            this._secTimer.dispose();
            return;
        }

        /* internal  */resize(): void
        {
            this._liftInfoText.y = this._bossInfoText.y + this._bossInfoText.textHeight + 10;
            this._listSp.y = this._liftInfoText.y + this._liftInfoText.textHeight + 10;
            this._rankLabel.y = this._listSp.y + this._listSp.height + 20;
            _bg.height = this._rankLabel.y + 30;
            return;
        }

        /* internal */ /* var */_secTimer: SecTimerView;

        /* internal */ /* var */_bossInfoText: GTextFiled;

        /* internal */ /* var */_liftInfoText: GTextFiled;

        /* internal */ /* var */_listSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_listPanel: GTileList;

        /* internal */ /* var */_listDp: DataProvider;

        /* internal */ /* var */_rankLabel: GTextFiled;

        /* internal */ /* var */_bossVec: Vector.<TBoss>;
    }
